<template>
    <div>
		<router-link :to='"/classmanager/classdetails/studentinformation?clazzId=" + this.$route.query.clazzId+"&clazzName="+this.$route.query.clazzName' class="navs">学生信息</router-link>
		<router-link :to='"/classmanager/classdetails/courseinformation?clazzId=" + this.$route.query.clazzId+"&clazzName="+this.$route.query.clazzName' class="navs">课程信息</router-link>
        <el-select class="select" v-model="url1" @change="To">
			<el-option 
				v-for="item in List" 
				:key="item.url" 
				:label="item.title"
				:value="item.url">
			</el-option>
		</el-select>
		<div class="btnBox">
			<el-button class="btn" type="success" @click="$router.push('/classmanager/classdetails/updatecourse?clazzId=' + $route.query.clazzId+'&clazzName='+$route.query.clazzName)" :disabled="couFlag">修改</el-button>
			<a href="#" @click="$router.push('/classmanager')">返回</a>
		</div>
        <div class="wrap">
			<h4>{{this.$route.query.clazzName}}课程表</h4>
			<h4 v-if="couFlag">暂无课表</h4>
			<el-table v-if="!couFlag" :data="tableData" border>
				<h4>{{ this.$route.query.clazzName }}课程表</h4>
				<el-table-column prop="level" label="">
				</el-table-column>
				<el-table-column label="周一">
					<template slot-scope="scope">
						<p>{{ scope.row.list[0].courseName }}</p>
						<p>{{ scope.row.list[0].courseTea }}</p>
					</template>
				</el-table-column>
				
				<el-table-column label="周二">
					<template slot-scope="scope">
						<p>{{ scope.row.list[1].courseName }}</p>
						<p>{{ scope.row.list[1].courseTea }}</p>
					</template>
				</el-table-column>
				<el-table-column label="周三">
					<template slot-scope="scope">
						<p>{{ scope.row.list[2].courseName }}</p>
						<p>{{ scope.row.list[2].courseTea }}</p>
					</template>
				</el-table-column>
				<el-table-column label="周四">
					<template slot-scope="scope">
						<p>{{ scope.row.list[3].courseName }}</p>
						<p>{{ scope.row.list[3].courseTea }}</p>
					</template>
				</el-table-column>
				<el-table-column label="周五">
					<template slot-scope="scope">
						<p>{{ scope.row.list[4].courseName }}</p>
						<p>{{ scope.row.list[4].courseTea }}</p>
					</template>
				</el-table-column>
				<el-table-column label="周六">
					<template slot-scope="scope" v-if="scope.row.list[5]">

						<p>{{ scope.row.list[5].courseName }}</p>
						<p>{{ scope.row.list[5].courseTea }}</p>
					</template>
				</el-table-column>
				<el-table-column label="周日">
					<template slot-scope="scope" v-if="scope.row.list[6]">
						<p>{{ scope.row.list[6].courseName }}</p>
						<p>{{ scope.row.list[6].courseTea }}</p>
					</template>
				</el-table-column>
			</el-table>
		</div>
    </div>
    
</template>

<script>
export default {
    data() {
		return {
			List:[
				{
					url:"/classmanager/classdetails/courseinformation/timetable?clazzId=" + this.$route.query.clazzId+"&clazzName="+this.$route.query.clazzName,
					title:'课程表'
				},
				{
					url:"/classmanager/classdetails/courseinformation/classcourses?clazzId=" + this.$route.query.clazzId+"&clazzName="+this.$route.query.clazzName,
					title:'添加科目'
				}
			],
			url1:'',
			baseUrl: require("../js/baseUrl.js").baseUrl,
			tableData: [],
			couFlag:true
		}
	},
	methods: {
		To(){
			// console.log(this.url1);
			this.$router.push(this.url1).catch(error=> error)
		},
		//获取课程表
		getCourse() {
			this.$http.post(this.baseUrl + 'SchoolSys/scha/searchByIClazz', {
				clazzId: Number(this.$route.query.clazzId),
			}).then(res => {
				// console.log(res);
				if (res.data.code == 200) {
					let resData = res.data.data
					//  console.log(resData)
					let datas = []
					for (var i in resData) {
						// console.log(resData[i])
						let list = [];
						for (var k in resData[i]) {
							list.push({
								courseName: resData[i][k].subName,
								courseTea: resData[i][k].teaName,
								week: k,
								weekIndex: k.substring(1, 2)
							})
						}
						//排序list
						for (var m = 0; m < list.length; m++) {
							for (var k = m + 1; k < list.length; k++) {
								if (list[m].weekIndex > list[k].weekIndex) {
									let temp = list[m]
									list[m] = list[k]
									list[k] = temp
								}
							}
						}

						datas.push({
							index: i.substring(1, 2),
							level: i,
							list: list
						})
					}
					// console.log(datas)

					for (var i = 0; i < datas.length; i++) {
						for (var k = i + 1; k < datas.length; k++) {
							if (datas[i].index > datas[k].index) {
								let temp = datas[i]
								datas[i] = datas[k]
								datas[k] = temp
							}
						}
					}

					this.tableData = datas
					// console.log(this.tableData)

					this.tableData.map(v=>{
						
						if(v.list==''){
							this.couFlag=true
						}else{
							this.couFlag=false
						}
					})
					
				}
			})
		}
	},
	mounted() {
		this.getCourse()
	},
}
</script>

<style>

</style>